import {ModuleMotionC, ModuleMotionData} from "../module/ModuleMotion";
import CreateMotionWindow_Generate from "../ui-generate/MotionEditor/CreateMotionWindow_generate";

export class CreateMotionWindow extends CreateMotionWindow_Generate{

    onStart(){
        this.bg.onClicked.add(()=>{
            mw.UIService.hide(CreateMotionWindow)
        })

        this.btn_create.onClicked.add(this.onClickCreate.bind(this))
    }

    onShow(){

    }

    private onClickCreate(){
        let md = ModuleService.getModule(ModuleMotionC)
        let mdData = DataCenterC.getData(ModuleMotionData)
        let name = this.input_name.text
        let frame = this.input_frame_count.text
        // 未输入
        if(name == '') return
        // 重名
        for (const key in mdData.sheets) {
            if(key == name){
                return;
            }
        }
        // 生成
        md.initMotion(name,frame == '' ? 1 : Number(frame))
        mw.UIService.hide(CreateMotionWindow)
    }
}